package main

import (
	"gin-kitex-gorm/dao"
	user "gin-kitex-gorm/kitex_gen/user/usersrv"
	"github.com/cloudwego/kitex/pkg/rpcinfo"
	"github.com/cloudwego/kitex/server"
	"log"
	"net"
	"os"
)

func main() {
	//r, err := etcd.NewEtcdRegistry([]string{"111.230.95.201:10079"}) // r should not be reused.
	//if err != nil {
	//	log.Fatal(err)
	//}

	err := dao.DbInit()
	if err != nil {
		os.Exit(-1)
	}

	addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:9092")

	svr := user.NewServer(new(UsersrvImpl), server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "user"}),
		server.WithServiceAddr(addr),
		// server.WithRegistry(r),
	)
	// https://www.cloudwego.io/docs/tutorials/framework-exten/registry/#integrate-into-kitex
	// server, err := echo.NewServer(new(EchoImpl), server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "echo"}), server.WithRegistry(r))
	//if err != nil {
	//	log.Fatal(err)
	//}

	// server.Run()
	err = svr.Run()

	if err != nil {
		log.Println(err.Error())
	}
}
